<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="index_style.css"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>upload file</title>
    </head>
    <body>

  <?php
        
 // Check if a file has been uploaded
    if(isset($_FILES['uploaded_file'])) {
    // Make sure the file was sent without errors
    if($_FILES['uploaded_file']['error'] == 0) {
        
        //Open connection with database
        $conn = @mysql_connect("localhost" , "root", "") or die(mysql_error());
        mysql_select_db("db_name") or die(mysql_error());

        }
        // Gather all required data
        $name = $_FILES['uploaded_file']['name'];
        $mime = $_FILES['uploaded_file']['type'];
        $data = $_FILES  ['uploaded_file']['tmp_name'];
        $size = intval($_FILES['uploaded_file']['size']);
        // Create the SQL query
        $query = "
            INSERT INTO `pdfs` (
                `file_name`, `type`, `size`, `data`, `date`
            )
            VALUES (
                '{$name}', '{$mime}', {$size}, '{$data}', NOW()
            )";
        // Execute the query
         mysql_query($query) or die(mysql_error());
        // Check if it was successfull
       if($query) { // if the query run successfully
            echo 'Success! Your file was successfully added!';
        }
        else {
            echo 'Error! Failed to insert the file';
               
        }
        // Close the mysql connection
        mysql_close($conn);
    }

    

// link to back to the main page
echo '<p>Click <a href="index.php">here</a> to go back</p>';
?>

        
        
        
        
        

